package springjdbc; /**
 * Copyright (c) 2018-2019 PoleStar Studio. All Rights Reserved. <br>
 * Use is subject to license terms.<br>
 * <p>
 * 在此处填写文件说明
 */

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * JUnit4测试类.
 * <p>说明.<br>
 *     使用@Test注解
 *     测试添加、更新、删除和查询账户信息。
 *
 * @version v1.0
 * @author lianzuozheng
 * @date 2019-04-21 -19:26
 */
public class JUnit4Test {

    ///** 1.指定Spring配置文件路径  */
    //String xmlPath= "edu/javaee/spring/springjdbc/beans.xml";
    ///** 2.创建Spring容器  */
    //ApplicationContext ac = new ClassPathXmlApplicationContext(xmlPath);
    ApplicationContext ac=new ClassPathXmlApplicationContext("springjdbc\\beans.xml");
    AccountDao accountDaoImpl = (AccountDao) ac.getBean("accountDaoImpl");

    @Test
    public void addAccountTest(){

        Account account = new Account();
        account.setUsername("tom");
        account.setBalance(2000.0);

        accountDaoImpl.addAccount(account);
    }

    @Test
    public void findAccountByIdTest(){
        Account account = accountDaoImpl.findAccountById(1);
        System.out.println(account);
    }

    @Test
    public void findAllAccountTest(){
        List<Account> accounts=accountDaoImpl.findAllAccount();
        for (Account account : accounts){
            System.out.println(account);
        }
    }
}
